package io.xiaojl.xj2ee.modules.sys.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import io.xiaojl.xj2ee.modules.sys.entity.SysUserRoleEntity;
import io.xiaojl.xj2ee.modules.sys.mapper.SysUserRoleEntityMapper;
import io.xiaojl.xj2ee.modules.sys.service.SysUserRoleService;


@Service("sysUserRoleService")
public class SysUserRoleServiceImpl implements SysUserRoleService {
	@Autowired
	private SysUserRoleEntityMapper sysUserRoleMapper;
	
	@Override
	public void saveOrUpdate(Long userId, List<Long> roleIdList) {
		if(roleIdList!=null){
			for(Long roleId: roleIdList){
				SysUserRoleEntity ur = new SysUserRoleEntity();
				ur.setUserId(userId);
				ur.setRoleId(roleId);
				sysUserRoleMapper.insertSelective(ur);
			}
		}
	}

	@Override
	public List<Long> queryRoleIdList(Long userId) {
		return sysUserRoleMapper.selectRoleIdByUserId(userId);
	}

	@Override
	public int deleteBatch(Long[] roleIds) {
		return sysUserRoleMapper.deleteBatch(roleIds);
	}

}
